'''
LastEditors: lf
Date: 2020-12-22 00:04:07
LastEditTime: 2020-12-27 23:39:45
FilePath: \021正则表达式\正则则表达式.py
'''
import re
#正则表达式
#字符串查找
#res = re.search(r"you", "i love you")
#print(res)

#通配符
#res = re.search(r".", "i love you")
#print(res)
#res = re.search(r"yo.", "i love you")
#print(res)
#消除通配符
#res = re.search(r"\.", "i love you.")
#print(res)
#匹配数字
#res = re.search(r"\d", "i love you 123")
#print(res)
#限制数值范围
#res = re.search(r'[0-255]', "182.168.3.1")
#print(res)
#限制重复匹配次数
#res = re.search(r'[0-255]', "182.168.3.1")
#print(res)
#限制匹配次数
#res = re.search(r'[0-255]{1}', "182.168.3.1")
#print(res)
#res = re.search(r'1{3}', "111.168.3.1")
#print(res)
#查找ip地址
#res = re.search(r'(([01]{0,1}\d{0,1}\d|[2]{0,1}[0-4]{0,1}\d|[2]{0,1}[5]{0,1}[0-5])\.){3}(25[0-5]|2{0,1}[0-4]{0,1}\d|1{0,1}\d{0,1}\d)', "255.255.255.255")
#print(res)


'''
description: 以下是特殊字符示例
param {*}
return {*}
'''
#通配符
#res = re.search(r'...', "i love you")
#print(res)

#或
#res = re.search(r'i|I', "i love you")
#print(res)
#res = re.search(r'i|I', "I love you")
#print(res)

#匹配字符串开始位置
#res = re.search(r'^i', "i love you")
#print(res)
#res = re.search(r'^y', "i love you")
#print(res)

#匹配字符串结束位置
#res = re.search(r'o$', "i love you")
#print(res)
#res = re.search(r'u$', "i love you")
#print(res)

'''
description: \ 
1、将普通字符变为特殊字符
2、解除元字符特殊功能
3、引用序号对应的子组所匹配的字符串
'''
#引用序号对应的子组所匹配的字符串
#res = re.search(r'(u)\1', "i love youuuu") #(u)\1 相当于 'uu'
#print(res)
#匹配单词边界
#res = re.findall(r"\byou\b", "i love you AND_you_?") #匹配第一个
#print(res)
#匹配非单词边界
#res = re.findall(r"\Byou\B", "i love you AND_you_") #匹配第二个
#print(res)

'''
description: [...]
*:匹配0次
+：匹配>1次
？：匹配0，1次
'''
#res = re.findall(r'[a-z]', "i love youuuu")
#print(res)

'''
description: search
param {*}
return {*}
'''
#res = re.search(r"(\w+) (\w+)", "i love you")
#print(res.group())
#print(res.start())
#print(res.end())


